local zhenxi = fk.CreateSkill{
    name = "os_heg__zhenxi",
}

local H = require "packages.ol_hegemony.util"

zhenxi:addEffect(fk.TargetSpecified,{
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(zhenxi.name) and
          data.card.trueName == "slash" and data.to then
          return true
        end
        return false
      end,
    on_cost = function(self, event, target, player, data)
        local choices = {}
        local room = player.room
        target = data.to
        if not target:isNude() then
        table.insert(choices, "os_heg__zhenxi_discard:" .. target.id)
        end
        table.insert(choices, "os_heg__zhenxi_use:" .. target.id)
        if H.getGeneralsRevealedNum(player) == 2 and H.getGeneralsRevealedNum(target) < 2 then
          table.insert(choices, "beishui_os_heg__zhenxi")
        end
        table.insert(choices, "Cancel")
        local choice = room:askToChoice(player, {choices = choices, skill_name = zhenxi.name, detailed = false})
        if choice ~= "Cancel" then
          event:setCostData(self,{tos = target, choice = choice})
          return true
        end
        return false
      end,
      on_use = function(self, event, target, player, data)
        local room = player.room
        target = data.to
        local choice = event:getCostData(self).choice
        if not choice:startsWith("os_heg__zhenxi_use") and not target:isNude() then
          local cards = room:askToChooseCards(player,{
            target = target,
            min = 1,
            max = 1,
            flag = "he",
            skill_name = zhenxi.name,
          })
          room:throwCard(cards, zhenxi.name, target, player)
        end
        if not choice:startsWith("os_heg__zhenxi_discard") then
          local success, dat = room:askToUseActiveSkill(player,{
            skill_name = "#os_heg__zhenxi_vs",
            prompt = "#os_heg__zhenxi-ask:"..target.id,
            cancelable =  true,
            extra_data = {bypass_distances = true, must_targets = {target.id}}
          })
          if success and dat then
            local card = dat.cards
            local c = Fk:cloneCard(Fk:getCardById(card[1]).suit == Card.Club and "supply_shortage" or "indulgence")
            c.skillName = zhenxi.name
            c:addSubcards(card)
            room:useCard({
              from = player,
              tos = { target },
              card = c,
              extra_data = { bypass_distances = true },
            })
          end
        end
      end,
})

Fk:loadTranslationTable{
    ["os_heg__zhenxi"] = "震袭",
    [":os_heg__zhenxi"] = "当你使用【杀】指定目标后，你可选择一项：1.弃置其一张牌；2.可将一张<font color='red'>♦</font>/♣非锦囊牌当【乐不思蜀】/【兵粮寸断】对其使用；若其有暗置武将牌且你武将牌均明置，则你可以执行两项。",

    ["os_heg__zhenxi_discard"] = "弃置 %src 一张牌",
    ["os_heg__zhenxi_use"] = "对 %src 使用延时锦囊",
    ["beishui_os_heg__zhenxi"] = "两项均执行",

    ["#os_heg__zhenxi-ask"] = "震袭：你可将一张<font color='red'>♦</font>/♣非锦囊牌当【乐不思蜀】/【兵粮寸断】对 %src 使用",
    ["#os_heg__zhenxi_vs"] = "震袭",

    ["$os_heg__zhenxi1"] = "戮胡首领，捣其王廷！",
    ["$os_heg__zhenxi2"] = "震疆扫寇，袭贼平戎！",
}

return zhenxi